<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>字符串回文函数封装</title>
</head>
<body>
    
</body>
<script>
    let str = 'abcba';
    
    function palind(str) {
        let strToArr1 = str.split('');
        let strToArr2 = [];

        //给strToArr2赋予新地址数组，这样改变strToArr2不会改变strToArr1。不同数组地址
        strToArr1.forEach(function (item) {
            strToArr2.push(item);
        })
        strToArr2.reverse();
        
        let arr1ToStr = strToArr1.join('');
        let arr2ToStr = strToArr2.join('');

        return arr1ToStr === arr2ToStr ? true : false;
    }
    console.log(palind(str))
</script>
</html>